package cn.com.chengq.filesshared.bean;

import cn.com.chengq.filesshared.App;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Arrays;

// @Component
public class MyBean implements CommandLineRunner, ApplicationRunner, ApplicationContextAware {
    private static final Logger log = LoggerFactory.getLogger(MyBean.class);

    private ApplicationContext ctx;

    @Override
    public void run(String... args) throws Exception {
        log.info("CommandLineRunner: {}", Arrays.asList(args));
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("ApplicationRunner: {}", Arrays.asList(args.getSourceArgs()));
        log.info("name: {}", args.getOptionValues("name"));
        log.info("NonOptions: {}", args.getNonOptionArgs());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx = applicationContext;
        Object obj = applicationContext.getBean("myConfig");
    }
}
